DAY2:String ends with?


Posted by birdbirdmurmur on 2023-07-15

題目連結:

解題過程:

  • 第一個想法是直接用includes(),以為可以輕鬆通過
    • 原以為includes()無法判斷string
      • 有想過要不要先判斷型態
    • 被自己笨死,看錯題目(請好好練英文x
  • 搞懂題目之後,翻開MDN字典
    • 使用endsWith()可快速判斷字串的結尾
      • 可以區分大小寫
  • Done.

解法:

function solution(str, ending){
  return str.endsWith(ending);
}

參考資料:


#javascript #Codewars #endWith







Related Posts

淺拷貝與深拷貝

淺拷貝與深拷貝

Stripe Follow Along Dropdown

Stripe Follow Along Dropdown

[ 筆記 ] 交換資料 - XMLHttpRequest、CORS、JSONP

[ 筆記 ] 交換資料 - XMLHttpRequest、CORS、JSONP


Comments